﻿Module Module1
    Public result As Decimal
    Public Function suma(ByVal num, ByVal num1) As Decimal
        result = num1 + num
        Return result
    End Function

    Public Function resta(ByVal num, ByVal num1) As Decimal
        result = num - num1
        Return result
    End Function

    Public Function produc(ByVal num, ByVal num1) As Decimal
        result = num1 * num
        Return result
    End Function

    Public Function divisionReal(ByVal num, ByVal num1) As Decimal
        If num = 0 Or num1 = 0 Then
            Console.WriteLine("Error el divisor es cero")
            result = 0
        Else
            result = num1 / num
            Return result
        End If
    End Function

    Public Function expo(ByVal num, ByVal num1) As Decimal
        result = num ^ num1
        Return result
    End Function

    Public Function divisionEntera(ByVal num, ByVal num1) As Decimal
        result = num \ num1
        Return result
    End Function


    Sub Main()
        Dim numSr, numSr1, operacion As String
        Dim num, num1 As Decimal
        Console.Title = "Calculadora"
        Do
            Console.Write("Número1 : ")
            numSr = Console.ReadLine()
        Loop While Not IsNumeric(numSr)

        num = Decimal.Parse(numSr)

        Do
            Console.Write("Número2 : ")
            numSr1 = Console.ReadLine()
        Loop While Not IsNumeric(numSr1)

        num1 = Decimal.Parse(numSr1)

        Console.Write("Operación a realizar " & ControlChars.NewLine) 'hace lo mismo que el write line
        Console.Write("S.-Suma " & ControlChars.NewLine)
        Console.Write("R.-Resta " & ControlChars.NewLine)
        Console.Write("P.-Producto " & ControlChars.NewLine)
        Console.Write("D.-División Real " & ControlChars.NewLine)
        Console.Write("C.-Cociente de división entera " & ControlChars.NewLine)
        Console.Write("E.-Exponente" & ControlChars.NewLine)
        Console.Write("Introduce una operacion a realizar ")
        operacion = Console.ReadLine()

        Select Case operacion.ToUpper
            Case "S"
                result = suma(num, num1)
            Case "R"
                result = resta(num, num1)
            Case "P"
                result = produc(num, num1)
            Case "D"
                result = divisionReal(num, num1)
            Case "C"
                result = divisionReal(num, num1)
            Case "E"
                result = expo(num, num1)
            Case Else
                Console.WriteLine("Opción no valida, Saliendo del programa")

        End Select

        Console.Write("El resultado de la operación es " & result)
        Console.ReadKey()
    End Sub

End Module
